// import { getExecutorList } from "@/api/modules/operation";
import { queryUserList } from "@/api/modules/fab";
import { formatAccountName } from "@/utils/common";
import { detectorIsolateTaskStatusMap as tagMapOption, detectorIsolateTypeMap } from "@/views/gas/utils";

/**
 * @description: 获取search配置信息
 * @return {Array<CommonSearch.SearchOption>}
 */
export const useSearchOption = (): Array<CommonSearch.SearchOption> => {
  const workOrderNo: CommonSearch.SearchOption = {
    label: "工单号",
    key: "workOrderNo",
    value: "",
    type: "input",
    placeholder: "请输入工单号",
    span: 5
  };
  const creator: CommonSearch.SearchOption = {
    label: "创建人",
    key: "creator",
    value: "",
    type: "select",
    remote: true,
    // selectRemoteApi: getExecutorList,
    // getParams: (realName: string) => ({ realName }),
    // mapOption: ({ realName: label = null, userId: value = null }) => ({ label, value }),
    selectRemoteApi: queryUserList,
    // getParams: (usernameLike: string) => ({ usernameLike, page: 1, pageSize: 9999 }), //  账号查询
    getParams: (realNameLike: string) => ({ realNameLike, page: 1, pageSize: 9999 }), //  姓名查询
    formatOption: (res: any) =>
      res?.data?.map(({ userId: value, username = "", realName = "" }: any) => ({ value, label: formatAccountName(username, realName) })),
    placeholder: "请输入创建人",
    span: 5
  };
  // 勿删 暂时注释
  // const taskType: CommonSearch.SearchOption = {
  //   label: "隔离类型",
  //   key: "taskType",
  //   value: "",
  //   type: "select",
  //   option: [
  //     {
  //       label: "纸带式",
  //       value: "PAPER_BAG"
  //     },
  //     {
  //       label: "标定",
  //       value: "SIGN"
  //     },
  //     {
  //       label: "施工",
  //       value: "CONSTRUCTION"
  //     }
  //   ],
  //   placeholder: "请选择隔离类型"
  // };
  const taskStatus: CommonSearch.SearchOption = {
    label: "状态",
    key: "taskStatus",
    value: "",
    type: "select",
    typeCode: "GAS_DETECTOR_TASK_STATUS",
    placeholder: "请选择状态",
    span: 5
  };
  const startTime: CommonSearch.SearchOption = {
    label: "创建日期",
    key: "startTime",
    realKeys: ["startTime", "endTime"],
    value: [],
    type: "daterange",
    span: 5
  };
  return [workOrderNo, creator, taskStatus, startTime];
};

/**
 * @description:  获取table表格的表头（cloumns）信息
 * @param {boolean} flag
 * @return {Array<CommonTable.TableCloumnsType>}
 */
export const useTableCloumns = (cb?: (scope: any) => void): Array<CommonTable.TableCloumnsType> => {
  const o_1 = {
    label: "工单号",
    prop: "workOrderNo",
    width: 120,
    cloumnClick(scope: any) {
      cb && cb(scope);
    }
  };
  const o_2 = {
    label: "侦测器",
    prop: "detectorCodes",
    width: 120
    // props: {
    //   "tooltip-options": {
    //     placement: "right"
    //   }
    // }
  };
  const o_2_1 = {
    label: "隔离类型",
    prop: "taskType",
    width: 80,
    render({ row }: any) {
      return () => detectorIsolateTypeMap.get(row?.taskType) || "--";
    }
  };
  const o_3 = {
    label: "状态",
    prop: "taskStatus",
    width: 100,
    tagMapOption,
    tagType: "point",
    defaultTagValue: 1,
    mapRow: ({ row: { taskStatus: value = "", taskStatusDesc: label = "" } }: any) => ({ value, label })
  };
  const o_4 = { label: "创建人", prop: "creatorName", width: 100 };
  const o_5 = { label: "隔离执行人", prop: "executorName", width: 100 };
  const o_6 = { label: "创建时间", prop: "createTime", width: 120 };
  const o_7 = { label: "完成时间", prop: "completedTime", width: 120 };
  const o_8 = { label: "用时", prop: "takeTime", width: 80 };
  return [o_1, o_2, o_2_1, o_3, o_4, o_5, o_6, o_7, o_8];
};
